using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TimeSheet.Protected
{
    /// <summary>
    /// Summary description for TotalsReport.
    /// </summary>
    public class TotalsReport : Page
    {
        protected Label lblProjectDateRange;
        protected DataGrid dgProjectTotals;
        protected DataGrid dgActivityTotals;
        protected Label lblActivityDateRange;

        private void Page_Load(object sender, EventArgs e)
        {
            BindProjectTotals();
            BindActivityTotals();

            lblActivityDateRange.Text = "From "
                                        + GetDateFrom().ToShortDateString() + " to "
                                        + GetDateTo().ToShortDateString();
            lblProjectDateRange.Text = lblActivityDateRange.Text;
        }

        private void BindProjectTotals()
        {
            dgProjectTotals.DataSource =
                TimeSheetBLL.Project.GetProjectTotalHoursByDate(
                    GetDateFrom(), GetDateTo());
            dgProjectTotals.DataBind();
        }

        private void BindActivityTotals()
        {
            dgActivityTotals.DataSource =
                TimeSheetBLL.Activity.GetActivityTotalHoursByDateRange(
                    GetDateFrom(), GetDateTo());
            dgActivityTotals.DataBind();
        }

        private DateTime GetDateFrom()
        {
            return Convert.ToDateTime(Server.UrlDecode(Request["from"]));
        }

        private DateTime GetDateTo()
        {
            return Convert.ToDateTime(Server.UrlDecode(Request["to"]));
        }

        #region Web Form Designer generated code

        protected override void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);
        }

        #endregion
    }
}